using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
using Microsoft.SqlServer.Management.Smo;

using Microsoft.SqlServer.Management.Common;
using System.Collections;
namespace Quanly_dethi.Class
{
    class csC_DapanCH
    {
        private ketnoi kn;

        public ketnoi Kn
        {
            get { return kn; }
            set { kn = value; }
        }
        private string databasename;

        public string Databasename
        {
            get { return databasename; }
            set { databasename = value; }
        }
        public csC_DapanCH()
        {
            Kn = new ketnoi();
            databasename = "";
        }
        public csC_DapanCH(string servername, string user, string pass, string dbname)
        {
            Kn = new ketnoi(servername ,user, pass);
            databasename = dbname;
        }
        public DataTable Sellect()
        { 
            Database db=Kn._Server.Databases[databasename];
            return db.ExecuteWithResults("select * from DapAnCH where Xoa='0'").Tables[0];
        }
        public DataTable Sellect(int ma)
        {
            string s = "select  * from DapAnCH where Xoa='0' and MaCH=" + ma + "";
            Database db = Kn._Server.Databases[databasename];
            return db.ExecuteWithResults(s).Tables[0];

        }
        public void Update(csE_DapanCH x)
        {
            string t = "update DapAnCH set MaCH=N'" + x.Mach + "', DapAn1='" + x.Da1 + "', DapAn2='" + x.Da2 + "', DapAn3='" + x.Da3 + "',  DapAn4='" + x.Da4 + "', DapAnDung='" + x.Dadung + "',Xoa='0' where MaDACH='" + x.Mada + "'";
            Database db=Kn._Server.Databases[databasename];
            db.ExecuteWithResults(t);

        }
        public void insert(csE_DapanCH x)
        {
            Database db = Kn._Server.Databases[databasename];
            string s = "insert into DapAnCH(MaCH, DapAn1, DapAn2,DapAn3,DapAn4,DapAnDung, Xoa) values('" + int.Parse(x.Mach.ToString()) + "','" + x.Da1.ToString() + "','" + x.Da2.ToString() + "','" + x.Da3.ToString() + "','" + x.Da4.ToString() + "','" + x.Dadung.ToString() + "','" + int.Parse(x.Xoa.ToString()) + "')";
            db.ExecuteWithResults(s);

        }
    }
}
